package cn.qihang.ssm.service.impl;

import cn.qihang.ssm.mapper.OrdersMapper;
import cn.qihang.ssm.mapper.ProductMapper;
import cn.qihang.ssm.pojo.Product;
import cn.qihang.ssm.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: qihang
 * @Date: 2022/10/31 15:36
 * @Desc:
 */
@Service
public class ProductServiceImpl implements ProductService {


    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private OrdersMapper orderMapper;

    /**
     * 查询所有产品
     * @param page
     * @param size
     * @return
     */
    @Override
    public List<Product> findAll(Integer page, Integer size) {
        return this.productMapper.findAll();
    }

    @Override
    public List<Product> findAll() {
        return this.productMapper.findAll();
    }

    /**
     * 新增产品
     * @param product
     */
    @Override
    public void save(Product product) {
        this.productMapper.save(product);
    }

    /**
     * 指定删除产品
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        //删除订单中商品外键
        this.orderMapper.updateById(id);
        //删除商品本身
        this.productMapper.deleteById(id);
    }


    /**
     * 修改产品之前的数据回显
     * 产品详情
     * @param id
     * @return
     */
    @Override
    public Product findById(Integer id) {
        return this.productMapper.findById(id);
    }


    /**
     * 修改产品
     * @param product
     */
    @Override
    public void edit(Product product) {
        this.productMapper.edit(product);
    }


}
